package com.itheima.mapper;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

    /***
     * 新增员工信息
     * useGeneratedKeys = true：使用新增数据的主键ID(自增ID)  66
     * keyProperty = "id":获取到主键值后，将主键值赋值给入参的哪个属性
     * @param emp
     */
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into emp(username,password,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) values(#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    /**
     * 查询所有员工信息
     */
    //@Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id=d.id limit #{start},#{pageSize}")
    //List<Emp> list(@Param("start") Integer start,@Param("pageSize") Integer pageSize);

    //基于PageHeler实现分页
    //@Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id=d.id")
    //List<Emp> list(@Param("name") String name,@Param("gender") Integer gender,@Param("begin") LocalDate begin,@Param("end") LocalDate end);
    List<Emp> list(EmpQueryParam empQueryParam);

    //批量删除员工信息
    int deleteByIds(List<Integer> ids);

    //根据ID查询员工信息
    Emp getById(Integer id);

    //根据员工ID修改员工信息
    int updateById(Emp emp);

    @MapKey(value = "pos")
    List<Map<String, Object>> countJobEmpData();

    @MapKey(value = "name")
    List<Map> countEmpGenderData();

    int deptEmpCount(Integer id);
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp login(Emp emp);


    /***
     * 查询总数量
     * @return
     */
    //@Select("select count(*) from emp")
    //Long count();
}
